﻿using msBsc.AppLogic.DataAlc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfTravelCarList : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void GetArea()
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                string cityId = this.GetParamHtValue("cityId");
                DataSet ds = cbcc.SelectCountryByParentId(cityId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string isAll = this.GetParamHtValue("isAll");
                if (isAll.ToLower() == "true")
                {
                    DataRow dr = ds.Tables[0].NewRow();
                    dr["COUNTRY_CITY_ID"] = "";
                    dr["COUNTRY_CITY_NME"] = "地区";
                    ds.Tables[0].Rows.InsertAt(dr, 0);
                }
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                string destionId = this.GetParamHtValue("destionId");
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                this.ExecJScript(@"updateSelet(""destionId_select""," + ret + @",""" + destionId + @""")");

            }
        }

        //获取景点
        private void GeCarList()
        {


            string cityId = this.GetParamHtValue("cityId");
            string countryId = this.GetParamHtValue("countryId");
            string destionId = this.GetParamHtValue("destionId");



            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicle = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                int pageRows = 20;
                int pageIndex = 0;
                int.TryParse(this.GetParamHtValue("pIndex"), out pageIndex);
                int vehicleType = 0;
                int.TryParse(this.GetParamHtValue("carType"), out vehicleType);

                string carPrice = this.GetParamHtValue("carPrice");
                string[] carPrices = carPrice.Split('-');
                decimal maxVehiclePrice = 0;

                if (carPrices.Length > 2)
                {
                    decimal.TryParse(carPrices[1], out maxVehiclePrice);
                }
                decimal minVehiclePrice = 0;
                decimal.TryParse(carPrices[0], out minVehiclePrice);

                DataSet ds = vehicle.GetVehicleForPageview(pageRows, pageIndex, destionId, cityId, countryId, vehicleType, 0, minVehiclePrice, maxVehiclePrice, 0, 0, 0, string.Empty);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 20, "");
                this.ExecJScript(@"layCarList(" + retJson + "," + ds.Tables[0].Rows[0]["ROWSCOUNT"] + ")");
            }

        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                GetArea();
                GeCarList();
            }
            else if (this.strAction == "getroute")
            {
                GeCarList();
            }
        }
    }
}